package com.dayatang.exam.repository;

import java.util.List;

import com.dayatang.exam.domain.Exam;
import com.dayatang.exam.domain.Registration;
import com.dayatang.exam.domain.RegistrationRepository;
import com.dayatang.exam.domain.User;
import com.dayatang.spring.repository.BaseEntityRepositoryHibernateSpring;

@SuppressWarnings("unchecked")
public class RegistrationRepositoryHibernate extends
		BaseEntityRepositoryHibernateSpring<Registration, Long> implements
		RegistrationRepository {
	
	public RegistrationRepositoryHibernate() {
		super(Registration.class);
	}

	@Override
	public List<Registration> findByExam(Exam exam) {
		return getHibernateTemplate().find("select o from Registration o where o.exam = ?", exam);
	}

	@Override
	public List<Registration> findByStudent(User student) {
		return getHibernateTemplate().find("select o from Registration o where o.student = ?", student);
	}

	@Override
	public List<User> findStudentsByExam(Exam exam) {
		return getHibernateTemplate().find("select o.student from Registration o where o.exam = ?", exam);
	}

	@Override
	public List<Exam> findExamsByStudent(User student) {
		return getHibernateTemplate().find("select o.exam from Registration o where o.student = ?", student);
	}

}
